<?php
namespace Admin\Controller;
use Think\Controller;
class BaceController extends Controller{
   
    public function _initialize(){
       if (!isset($_COOKIE['name'])) {
           $this->redirect("Admin/Login/login");
          
       }
       
       //权限验证
       $a=$this->getRolePrivilege();
      
       
       //$c=$_SERVER['PHP_SELF'];
/* 
 * 
 *MODULE_NAME.'/'.CONTROLLER_NAME.'/'.ACTION_NAME
 *获取当前的  /模块名/控制器 /方法名
 */    /*     
        if (!in_array(MODULE_NAME.'/'.CONTROLLER_NAME.'/'.ACTION_NAME,$a)) {
           $this->redirect("Admin/A/a");
           
       }  */
     
      }
      public function getRolePrivilege() {
          $uid=$_COOKIE['id'];
          //根据登录用户查找相对应的角色
          $n=0;
          $re=M('User_role')->where("uid=$uid")->field("role_id")->find();
          foreach ($re as $v) {
              $role=M('Role')->where("id=$v")->select();
              foreach ($role as $v) {
                  $role_access=M('Role_access')->where("role_id={$v['id']}")->field('access_id')->select();

                 foreach ($role_access as $k=>$v) {
                      $id=$v['access_id'];//查询角色对应的权限urls
                      $re=M('Access')->where("id={$id}")->field("urls")->select();
                       $access[$k]=$re[0];
                       
                    foreach ($access[$k] as $k=>$v) {
                        
                        $urls[$n]=json_decode($v);
                       
                        $n++; 
                    }
                 }
             }
         }
          
         return $urls;
     }
     
}



        //取出指定用的角色

      
        
  

